package cn.yerly.sakura.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * A TradeComment.
 */
@Entity
@Table(name = "TRADECOMMENT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName="tradecomment")
public class TradeComment implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Min(value = 0)
    @Column(name = "rank", nullable = false)
    private Integer rank;

    @NotNull
    @Column(name = "type", nullable = false)
    private Integer type;

    @Column(name = "comment")
    private String comment;

    @Column(name = "disabled")
    private Boolean disabled;

    @OneToOne
    private User user;

    @ManyToOne
    private Trade trade;

    @ManyToOne
    private TradeItem tradeItem;

    @ManyToOne
    private TradeComment tradeComment;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getRank() {
        return rank;
    }

    public void setRank(Integer rank) {
        this.rank = rank;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Boolean getDisabled() {
        return disabled;
    }

    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Trade getTrade() {
        return trade;
    }

    public void setTrade(Trade trade) {
        this.trade = trade;
    }

    public TradeItem getTradeItem() {
        return tradeItem;
    }

    public void setTradeItem(TradeItem tradeItem) {
        this.tradeItem = tradeItem;
    }

    public TradeComment getTradeComment() {
        return tradeComment;
    }

    public void setTradeComment(TradeComment tradeComment) {
        this.tradeComment = tradeComment;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        TradeComment tradeComment = (TradeComment) o;

        if ( ! Objects.equals(id, tradeComment.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "TradeComment{" +
                "id=" + id +
                ", rank='" + rank + "'" +
                ", type='" + type + "'" +
                ", comment='" + comment + "'" +
                ", disabled='" + disabled + "'" +
                '}';
    }
}
